home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-06 / an201x.zip / VIEWINVN.C < prev    next >
C/C++ Source or Header  |  1991-12-17  |  2KB  |  70 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <nit.h>
  5. #include "btrieve.h"
  6. #include "datafile.h"
  7.  
  8. #define PROGRAM_NAME "VIEWINVN"
  9.  
  10. void Usage(void);
  11.  
  12. void main(int argc, char **argv)
  13. {
  14.     char    dbPath[80] = "\\PUBLIC\\INVENTRY.BTR";
  15.     int    iLoadedBtrieve = FALSE;
  16.     int    status;
  17.  
  18.     if (argc == 2)
  19.         strcpy(dbPath, argv[1]);
  20.     else if (argc > 2) {
  21.         printf("%s--view records in data file created by INVENTRY program\n", PROGRAM_NAME);
  22.         printf("Usage:\n");
  23.         printf("\t%s [path]\n", PROGRAM_NAME);
  24.         printf("\tpath     data file path\n");
  25.         printf("\t         default path is %s\n", dbPath);
  26.         exit(1);
  27.     }
  28.  
  29.     if (!(DataFileExists(dbPath))) {
  30.         printf("%s: data file %s not found\n", PROGRAM_NAME, dbPath);
  31.         exit(1);
  32.     }
  33.  
  34.     if (!(BtrieveIsLoaded())) {
  35.         LoadBtrieve();
  36.         if (!(BtrieveIsLoaded())) {
  37.             printf("Unable to load Btrieve record manager\n");
  38.             exit(1);
  39.         }
  40.         iLoadedBtrieve = TRUE;
  41.     }
  42.  
  43.     status = OpenDataFile(dbPath);
  44.     if (status) {
  45.         printf("Unable to open file %s\n", dbPath);
  46.         printf("Btrieve error code %d\n", status);
  47.         exit(1);
  48.     }
  49.  
  50.     status = ListItems();
  51.     if (status) {
  52.         printf("Unable to display inventory data\n");
  53.         printf("Btrieve error code %d\n", status);
  54.     }
  55.  
  56.     status = CloseDataFile();
  57.     if (status) {
  58.         printf("Unable to close inventory data file\n");
  59.         printf("Btrieve error code %d\n", status);
  60.     }
  61.  
  62.     if (iLoadedBtrieve) {
  63.         status = UnloadBtrieve();
  64.         if (status) {
  65.             printf("Unable to unload Btrieve record manager\n");
  66.             printf("Btrieve error code %d\n", status);
  67.         }
  68.     }
  69. }
  70.